import { BasicColumn } from '@/components/Table';
import { FormSchema } from '@/components/Table';
import { h } from 'vue';
import Icon from '@/components/Icon/Icon.vue';

export const columns: BasicColumn[] = [
  {
    title: '名称',
    align: 'center',
    dataIndex: 'name',
    width: 200,
    customRender: ({ record }) => {
      return h('span', {}, [
        record.success === 'Y'
          ? h(Icon, {
              icon: 'clarity:success-standard-line',
              color: 'green',
              style: 'float: left',
            })
          : h(Icon, {
              icon: 'material-symbols:cancel-outline-rounded',
              color: 'red',
              style: 'float: left',
            }),
        record.name,
      ]);
    },
  },
  {
    title: '操作类型',
    align: 'center',
    dataIndex: 'opType',
  },
  {
    title: 'ip',
    align: 'center',
    dataIndex: 'ip',
  },
  {
    title: '地址',
    align: 'center',
    dataIndex: 'location',
  },
  {
    title: '浏览器',
    align: 'center',
    dataIndex: 'browser',
  },
  {
    title: '操作系统',
    align: 'center',
    dataIndex: 'os',
  },
  {
    title: '请求地址',
    align: 'center',
    dataIndex: 'url',
  },
  {
    title: '类名称',
    align: 'center',
    dataIndex: 'className',
  },
  {
    title: '方法名称',
    align: 'center',
    dataIndex: 'methodName',
  },
  {
    title: '请求方式（GET POST PUT DELETE)',
    align: 'center',
    dataIndex: 'reqMethod',
  },
  {
    title: '请求参数',
    align: 'center',
    dataIndex: 'param',
  },
  {
    title: '返回结果',
    align: 'center',
    dataIndex: 'result',
    sorter: true,
  },
  {
    title: '操作时间',
    align: 'center',
    dataIndex: 'opTime',
    sorter: true,
  },
  {
    title: '操作账号',
    align: 'center',
    dataIndex: 'account',
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'opTime',
    label: '日志时间',
    component: 'RangePicker',
    colProps: { span: 8 },
    required: false,
    componentProps: {
      style: {
        width: '100%',
      },
    },
  },
  {
    field: 'name',
    label: '名称',
    component: 'Input',
    required: false,
    colProps: { span: 8 },
  },
  {
    field: 'success',
    label: '是否执行成功',
    component: 'ApiSelect',
    defaultValue: 'N',
    componentProps: {
      dictCode: 'yes_or_no',
    },
    colProps: { span: 8 },
    required: false,
  },
];
